package com.attedu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLOutput;
import java.util.Scanner;

/**
 * @author tune_the last
 * @date 2025/11/3 - 17:44
 */
public class Demo03JDBC {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8", "root", "ASD13579asd");
        Scanner in = new Scanner(System.in);
        String sql = "UPDATE user SET password = ? WHERE username = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        System.out.print("请输入您的用户名：");
        preparedStatement.setString( 2, in.next());
        System.out.print("请输入修改后的密码：");
        preparedStatement.setString( 1, in.next());
        int i = preparedStatement.executeUpdate();
        if (i > 0){
            System.out.println("修改成功！");
        }else {
            System.out.println("修改失败！");
        }
        connection.close();
    }
}
